#include "wind.h"

Wind::Wind(b2Vec2 force)
    : ForceWrapper(force),
      time(0)
{

}

void Wind::step()
{
    ++ time;
    int r = rand() % 8;
    r = r & 0x01 ? r : -r;
    time += r;
}

b2Vec2 Wind::getForce()
{
    float len = sqrt(force.x * force.x + force.y * force.y);
    float angle = time / 100.0 + asin(force.y / len);
    return b2Vec2(cos(angle) * len, sin(angle) * len);
}

ForceWrapper *Wind::clone()
{
    return new Wind(this->force);
}
